//通用处理
export const processMixins = {
  data() {
    return {
      processInstanceId: null,
      processImageVisible: false
    }
  },
  props: {},

  methods: {
    onCopy() {
      this.$message.success("复制成功!")
    },
    claimTask(task) {
      this.http.post(this, {
        url: this.api.tasktodo.claim,
        data: {
          taskId: task.taskId
        },
        success: (me, data) => {
          this.$refs.table.refresh()
        }
      })
    },
    /**
     * 启动流程
     * @param businessKey
     * @param handlerName
     */
    startProcess(businessKey, handlerName, content) {
      this.http.confirm(this, {
        content: content || "确认启动流程吗?",
        url: this.api.processInstance.start,
        requestBody: true,
        data: {
          handlerName: handlerName,
          businessKey: businessKey
        },
        success: (me, data) => {
          this.$refs.table.refresh()
        }
      })
    },
    //重新提交
    completeTask(record) {
      this.http.confirm(this, {
        content: "确认提交吗?",
        url: this.api.tasktodo.complete,
        requestBody: true,
        data: {
          taskId: record.taskId
        },
        success: (me, data) => {
          this.$refs.table.refresh()
        }
      })
    },
    unClaimTask(task) {
      this.http.put(this, {
        url: this.api.tasktodo.unclaim,
        data: {
          taskId: task.taskId
        },
        success: (me, data) => {
          this.$refs.table.refresh()
        }
      })
    },
    /**
     * 流程进度
     * @param result
     */
    processImg(result, processInstanceId) {
      this.processInstanceId = processInstanceId || result.processInstanceId
      this.processImageVisible = true
    },
    /**
     * 删除流程实例
     * @param task
     */
    deleteProcessInstance(processInstanceId, handlerName) {
      if (processInstanceId) {
        this.http.confirm(this, {
          content: "该操作将流程恢复为未提交状态,确认执行吗?",
          url: this.api.processInstance.remove,
          data: {
            ids: processInstanceId,
            cascade: true,
            handlerName: handlerName
          },
          success: function(me, data) {
            me.$refs["table"].refresh(false)
          }
        })
      } else {
        this.$message.success("流程实例ID不存在!")
      }
    }
  }
}
